﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Person.Search;

namespace University.Workshop.Presentation.Person
{
    /// <summary>
    /// Interaction logic for SearchPerson.xaml
    /// </summary>
    public partial class SearchPerson : Page, ISearchPersonView
    {
        PresenterSearchPerson pSearchPerson;
        public SearchPerson()
        {
            InitializeComponent();
            pSearchPerson = new PresenterSearchPerson(this);
        }

        public ICollection<Model.Person> personFinded
        {
            get
            {
                if (PersonFindeddDgv.ItemsSource == null)
                    new List<Model.Person>();
                return (ICollection<Model.Person>)PersonFindeddDgv.ItemsSource;
            }
            set
            {
                PersonFindeddDgv.ItemsSource = null;
                PersonFindeddDgv.ItemsSource = value;    
            }
        }

        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }
        public void NotifySystemMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public string PersonId
        {
            get
            {
                return PersonIdRelativeTxBx.Text.ToString();
            }
            set
            {
                PersonIdRelativeTxBx.Text = value;
            }
        }

        public string PersonNamesRelative
        {
            get
            {
                return PersonNameRelativeTxbx.Text.ToString();
            }
            set
            {
                PersonNameRelativeTxbx.Text = value;
            }
        }

        public string PersonLastNamesRelative
        {
            get
            {
                return PersonLastNamesTxbx.Text.ToString();
            }
            set
            {
                PersonLastNamesTxbx.Text = value;
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Persona";
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchPerson.SearchPerson();
        }

        private void ShowPersonBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Person.ReadPerson((Model.Person)PersonFindeddDgv.SelectedItem));
        }

        private void ModifyPersonBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Person.ModifyPerson((Model.Person)PersonFindeddDgv.SelectedItem));
        }
    }
}
